<?php


namespace app\index\controller;


use app\common\controller\Frontend;

class Wxlogin extends Frontend
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    // protected $layout = '';

    /**
     * 获取微信用户数据
     *
     */
    public function  _initialize(){
        $this->appId = 'wxefd3ee203bd5a330';  //wxe6747dc052817254
        $this->appSecret = '8f01274945695e2f8693db315f142487';  //
    }


    public function wxindex()
    {

        $this->Wxsdk = new Wxsdk($this->appId,$this->appSecret);

        if(!$this->Wxsdk->islogin()){
            $user = $this->Wxsdk->login();
            if(!empty($user['openid'])){
                //存数据库
                $this->add_Wxuser($user);//获取到微信用户  存数据

                // 然后继续操作
            }else{
                $this->success('error', $user);
            }

        }

    }

    public function add_Wxuser($user){
        //在你的数据库 添加用户信息
        dump($user);
    }
}